﻿using System;
using System.Net;

using Newtonsoft.Json;
using System.Collections.Generic;

namespace Tulde.Windows.Music.ViewModel
{
    [JsonObject()]
    public class Track
    {
        [JsonProperty("trackId")]
        public string TrackId { get; set; }
        [JsonProperty("trackTitle")]
        public string TrackTitle { get; set; }
        [JsonProperty("trackNumber")]
        public string TrackNumber { get; set; }
        [JsonProperty("trackLength")]
        public long? TrackLength { get; set; }
        [JsonProperty("trackfilename")]
        public string TrackFileName { get; set; }
        [JsonProperty("trackfilesize")]
        public long? TrackFileSize { get; set; }
        [JsonProperty("downloadurl")]
        public string DownloadUrl { get; set; }


        [JsonProperty("albumId")]
        public string AlbumId { get; set; }
        [JsonProperty("albumTitle")]
        public string AlbumTitle { get; set; }
        [JsonProperty("albumYear")]
        public string AlbumYear{ get; set; }
        [JsonProperty("artistName")]
        public string ArtistName { get; set; }
        [JsonProperty("playURL")]
        public string PlayURL { get; set; }
        [JsonProperty("playmixURL")]
        public string PlaymixURL { get; set; }
        [JsonProperty("trackFileKey")]
        public string TrackFileKey { get; set; }
        [JsonProperty("albumArtURL")]
        public string AlbumArtUrl { get; set; }

        public double GetTimeInMinutes()
        {
            double d = this.TrackLength.HasValue ? this.TrackLength.Value : 0;
            double divisor = 60000;
            if (d > 0)
            {
                return d / divisor;
            }
            else
            {
                return 0;
            }
        }
        public string GetUrlFix()
        {
            return this.PlayURL + "&ext=.mp3";
        }
        public Track()
        {

        }
    }
    [JsonObject()]
    public class TrackResult
    {
        [JsonProperty("summary")]
        public Summary Summary { get; set; }

        [JsonProperty("trackList")]
        public List<Track> Tracks { get; set; }
    }
}
